package org.metasketch.demo.model;

import java.util.ArrayList;
import java.util.List;

import org.metasketch.editor.toolbox.advanced.DeleteRelatedManager;
import org.metasketch.model.BaseModel;
import org.metasketch.model.CommonIdentified;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("demo-model")
public class DEMOModel extends BaseModel {

	{
		DeleteRelatedManager.registerDependency(CoordinationLink.class,
				"source", "target");
	}

	List<TransactionKind> transactions = new ArrayList<TransactionKind>();

	@XStreamAlias("actor-roles")
	List<ActorRole> actorRoles = new ArrayList<ActorRole>();

	@XStreamAlias("organizational-functions")
	List<OrganizationalFunction> organizationalFunctions = new ArrayList<OrganizationalFunction>();

	@XStreamAlias("organization-units")
	List<OrganizationalUnit> organizationUnits = new ArrayList<OrganizationalUnit>();

	@XStreamAlias("coordination-links")
	List<CoordinationLink> coordinationLinks = new ArrayList<CoordinationLink>();

	public void compileIndex() {
		super.compileIndex();

		for (TransactionKind object : transactions) {
			index.storeNode(object);
		}

		for (ActorRole object : actorRoles) {
			index.storeNode(object);
		}

		for (OrganizationalFunction object : organizationalFunctions) {
			index.storeNode(object);
		}

		for (OrganizationalUnit object : organizationUnits) {
			index.storeNode(object);
		}

		for (CoordinationLink object : coordinationLinks) {
			index.storeNode(object);
		}

		for (TransactionKind object : transactions) {
			index.storeNode(object);
		}

	}

	public void addChild(CommonIdentified node) {
		super.addChild(node);

		if (node instanceof TransactionKind) {
			transactions.add((TransactionKind) node);
		} else if (node instanceof ActorRole) {
			actorRoles.add((ActorRole) node);
		} else if (node instanceof OrganizationalFunction) {
			organizationalFunctions.add((OrganizationalFunction) node);
		} else if (node instanceof OrganizationalUnit) {
			organizationUnits.add((OrganizationalUnit) node);
		} else if (node instanceof CoordinationLink) {
			coordinationLinks.add((CoordinationLink) node);
		}

		// index.storeNode(node);

	}

	public void removeChild(CommonIdentified node) {
		super.removeChild(node);

		if (node instanceof TransactionKind) {
			transactions.remove((TransactionKind) node);
		} else if (node instanceof ActorRole) {
			actorRoles.remove((ActorRole) node);
		} else if (node instanceof OrganizationalFunction) {
			organizationalFunctions.remove((OrganizationalFunction) node);
		} else if (node instanceof OrganizationalUnit) {
			organizationUnits.remove((OrganizationalUnit) node);
		} else if (node instanceof CoordinationLink) {
			coordinationLinks.remove((CoordinationLink) node);
		}

		// index.removeNode(node);

	}

	public List<TransactionKind> getTransactions() {
		return transactions;
	}

	public void setTransactions(List<TransactionKind> transactions) {
		this.transactions = transactions;
	}

	public List<ActorRole> getActorRoles() {
		return actorRoles;
	}

	public void setActorRoles(List<ActorRole> actorRoles) {
		this.actorRoles = actorRoles;
	}

	public List<OrganizationalFunction> getOrganizationalFunctions() {
		return organizationalFunctions;
	}

	public void setOrganizationalFunctions(
			List<OrganizationalFunction> organizationalFunctions) {
		this.organizationalFunctions = organizationalFunctions;
	}

	public List<OrganizationalUnit> getOrganizationUnits() {
		return organizationUnits;
	}

	public void setOrganizationUnits(List<OrganizationalUnit> organizationUnits) {
		this.organizationUnits = organizationUnits;
	}

	public List<CoordinationLink> getCoordinationLinks() {
		return coordinationLinks;
	}

	public void setCoordinationLinks(List<CoordinationLink> coordinationLinks) {
		this.coordinationLinks = coordinationLinks;
	}

}
